package maiyatian.videolive.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import maiyatian.videolive.IActivity;
import maiyatian.videolive.R;
import maiyatian.videolive.fragment.setting.AboutUsFragment;
import maiyatian.videolive.fragment.setting.AccountSafeFragment;
import maiyatian.videolive.fragment.setting.BlackListFragment;
import maiyatian.videolive.fragment.setting.HelpFeedbackFragment;
import maiyatian.videolive.fragment.setting.PushManageFragment;

/**
 * Created by 王中阳 on 2016/5/10.
 */
@ContentView(R.layout.activity_setting)
public class SettingActivity extends IActivity implements View.OnClickListener {
    public static final String TAG = "SettingActivity";
    //fragment初始化及实例化
    SettingActivity mycontext;
    ActionBar ab;
    @ViewInject(R.id.titleBar)
    TextView titleBar;
    @ViewInject(R.id.back)
    ImageView back;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);
        back.setOnClickListener(this);
        mPageTo = SettingActivity.this.getIntent().getStringExtra(IActivity.PAGETO);
        switchFragment(mPageTo);
    }

    private void switchFragment(String mPageTo) {
        Fragment fragment = null;
        switch (mPageTo) {
            case AboutUsFragment.TAG:
                fragment = AboutUsFragment.newInstance();
                titleBar.setText(getResources().getString(R.string.aboutUs));
                break;
            case AccountSafeFragment.TAG:
                fragment = AccountSafeFragment.newInstance();
                titleBar.setText(getResources().getString(R.string.accountSafe));
                break;
            case BlackListFragment.TAG:
                fragment = BlackListFragment.newInstance();
                titleBar.setText(getResources().getString(R.string.blackList));
                break;
            case HelpFeedbackFragment.TAG:
                fragment = HelpFeedbackFragment.newInstance();
                titleBar.setText(getResources().getString(R.string.feedback));
                break;
            case PushManageFragment.TAG:
                fragment = PushManageFragment.newInstance();
                titleBar.setText(getResources().getString(R.string.push));
                break;
        }
        if (fragment != null) {
            getSupportFragmentManager().beginTransaction().replace(R.id.frameSetting, fragment).commit();
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.back:
                this.finish();
                break;
        }
    }
}
